package com.swiftride.controller.app;

import com.swiftride.pojo.domain.Order;
import com.swiftride.pojo.param.ConfirmFeesParam;
import com.swiftride.pojo.param.CreateOrderParam;
import com.swiftride.pojo.param.DriverOrderParam;
import com.swiftride.pojo.vo.DriverLocationVo;
import com.swiftride.pojo.vo.DriverOrderMonthVo;
import com.swiftride.pojo.vo.OrderDetailVo;
import com.swiftride.pojo.vo.OrderInfoVo;
import com.swiftride.result.R;
import com.swiftride.service.IOrderService;
import com.swiftride.service.impl.ITencentDistanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@Tag(name = "小程序订单表", description = "小程序订单表")
@RestController
@RequestMapping("/app/order")
public class AppOrderController {

    @Autowired
    public IOrderService orderService;

    @Autowired
    public ITencentDistanceService tencentDistanceService;

    //----------业务实现方法----------
    @Operation(summary = "创建订单", description = "创建订单接口")
    @Parameter(name = "createOrderParam", description = "订单参数对象", required = true)
    @PostMapping("/createOrder")
    public R<Order> createOrder(@RequestBody @NotNull CreateOrderParam createOrderParam) {
        return R.success(orderService.createOrder(createOrderParam));
    }

    @Operation(summary = "司机拉取订单", description = "司机拉取订单接口")
    @GetMapping("/driver/pullOrder")
    public R<List<OrderInfoVo>> driverPullOrder() {
        return R.success(orderService.driverPullOrder());
    }


    @Operation(summary = "司机秒杀订单", description = "司机秒杀订单接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/driver/killOrder/{orderNo}")
    public R<Order> killOrder(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        return R.success(orderService.killOrder(orderNo));
    }

    @Operation(summary = "乘客取消订单", description = "乘客取消订单接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/customer/cancelOrder/{orderNo}")
    public R<Void> customerCancelOrder(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        orderService.customerCancelOrder(orderNo);
        return R.success();
    }

    @Operation(summary = "司机取消订单", description = "司机取消订单接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/driver/cancelOrder/{orderNo}")
    public R<Void> driverCancelOrder(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        orderService.driverCancelOrder(orderNo);
        return R.success();
    }

    @Operation(summary = "到达代驾点", description = "到达代驾点接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @PostMapping("/driver/arrive/{orderNo}")
    public R<Void> arriveStartPlace(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        orderService.arriveStartPlace(orderNo);
        return R.success();
    }

    @Operation(summary = "开始代驾", description = "开始代驾接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @PostMapping("/driver/start/{orderNo}")
    public R<Void> startDriving(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        orderService.startDriving(orderNo);
        return R.success();
    }

    @Operation(summary = "结束代驾", description = "结束代驾接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @PostMapping("/driver/end/{orderNo}")
    public R<Void> endDriving(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        tencentDistanceService.endDriving(orderNo);
        return R.success();
    }

    @Operation(summary = "确认费用", description = "确认费用接口")
    @Parameter(name = "confirmFeesParam", description = "确认费用参数", required = true)
    @PostMapping("/driver/confirmFees")
    public R<Void> confirmFees(@RequestBody ConfirmFeesParam confirmFeesParam) {
        orderService.confirmFees(confirmFeesParam);
        return R.success();
    }

    @Operation(summary = "发送账单", description = "发送账单接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @PostMapping("/driver/confirmFees/{orderNo}")
    public R<Void> sendOrderBill(@PathVariable(value = "orderNo") String orderNo) {
        //orderService.sendOrderBill(orderNo);
        return R.success();
    }

    //----------业务查询方法----------
    @Operation(summary = "获取正在进行订单信息", description = "获取正在进行订单信息接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/{orderNo}")
    public R<Order> getProgressOrder(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        return R.success(orderService.getProgressOrder(orderNo));
    }

    @Operation(summary = "乘客查看订单详情", description = "乘客查看订单详情接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/customer/orderDetail/{orderNo}")
    public R<OrderDetailVo> getCustomerOrderDetail(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        return R.success(orderService.getCustomerOrderDetail(orderNo));
    }

    @Operation(summary = "司机查看订单详情", description = "司机查看订单详情接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/driver/orderDetail/{orderNo}")
    public R<OrderDetailVo> getDriverOrderDetail(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        return R.success(orderService.getDriverOrderDetail(orderNo));
    }

    @Operation(summary = "乘客定时获取当前订单是否被接单", description = "乘客定时获取当前订单是否被接单接口")
    @Parameter(name = "orderNo", description = "订单编号", required = true)
    @GetMapping("/customer/schedule/orderAccept/{orderNo}")
    public R<Boolean> getOrderAccept(@PathVariable(value = "orderNo") @NotBlank String orderNo) {
        return R.success(orderService.getOrderAccept(orderNo));
    }

    @Operation(summary = "乘客定时查询司机位置", description = "乘客定时查询司机位置接口")
    @Parameter(name = "driverId", description = "司机id", required = true)
    @GetMapping("/customer/schedule/driverLocation/{driverId}")
    public R<DriverLocationVo> getDriverLocation(@PathVariable(value = "driverId") @NotBlank String driverId) {
        return R.success(orderService.getDriverLocation(driverId));
    }

    //----------小程序页面退出后重新进入,维护页面的方法----------
    @Operation(summary = "乘客获取最近一次订单", description = "获取乘客最近一次订单接口")
    @GetMapping("/customer/lastOrder")
    public R<Order> getCustomerLastOrder() {
        return R.success(orderService.getCustomerLastOrder());
    }

    @Operation(summary = "司机获取当前工作状态", description = "获取司机工作状态接口")
    @GetMapping("/driver/workStatus")
    public R<Order> getDriverWorkStatus() {
        return R.success(orderService.getDriverWorkStatus());
    }

    @Operation(summary = "司机获取订单列表", description = "司机获取订单列表接口")
    @Parameter(name = "driverOrderParam", description = "司机订单查询条件对象", required = true)
    @PostMapping("/driver/list")
    public R<List<DriverOrderMonthVo>> getDriverOrder(@RequestBody DriverOrderParam driverOrderParam) {
        return R.success(orderService.getDriverOrder(driverOrderParam));
    }
}
